< previous page page_340 next page >

Page 340
Err.Number
The Err.Number property returns a number associated with the error that occurred. The error numbers are broken up into different categories. If Err.Number returns a zero, no error has occurred. You can check for specific errors by comparing the Err.Number property against a certain value.
Err.Description
The Err.Description property returns a short string describing the last error that occurred. This string can sometimes be used to display a message to the user. However, these messages are generally pretty cryptic. Its my recommendation that you come up with more descriptive error messages.
Lets take a look at an example:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdErrObject_Click()
   On Error GoTo Error_EH

   Stop

   txtResult = CInt(txtDividend) / CInt(txtDivisor)

   Exit Sub

Error_EH:
   If Err.Number = 11 Then
      MsgBox "A Divide By Zero Error Has Occurred"
   Else
      MsgBox Err.Description
   End If
   Err.Clear

   Exit Sub
End Sub
In this example, you can see that you can check for a specific Divide By Zero error number. If that error number is received, the user has input some bad data. If its not the error number 11, you should display the Description property from the error object so the user can at least get some other error information.

 
< previous page page_340 next page >

If you like this book, buy it!